package system.task.quartz;

import lombok.SneakyThrows;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.message.BasicNameValuePair;
import system.task.TaskExecutor;

import java.nio.charset.Charset;

/**
 * HTTP get job
 */
public class HttpGetJob extends HttpJob implements TaskExecutor {

    public HttpGetJob(String url) {
        super(url);
    }

    @SneakyThrows
    @Override
    protected HttpUriRequest createRequest(URIBuilder builder, HttpJobParam jobParam, HttpClient httpClient) {
        for (BasicNameValuePair param : jobParam.param) {
            builder.addParameter(param.getName(), param.getValue());
        }
        builder.setCharset(Charset.forName(jobParam.charset));
        HttpGet httpGet = new HttpGet(builder.build());
        return httpGet;
    }

}
